home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Demos / A.D. Software / OOFILE 1.3b4d6.sit / OOFILE 1.3b4d6 / MacCodeWarriorDemo1.3b4d6 / docs / samples / ooftst09.cpp / ooftst09.cpp
Encoding:
C/C++ Source or Header  |  1997-03-18  |  3.1 KB  |  125 lines  |  [TEXT/CWIE]

  1. // Copyright 1994 A.D. Software. All Rights Reserved
  2.  
  3. // OOFTEST9
  4.  
  5. // this sample deletes records including related data
  6.  
  7. // Simple stream I/O is used to interact with the user.
  8. #include "oofile.h"
  9.  
  10.  
  11. #include "ooftst02.h"
  12.  
  13. // global variables that define the database using the ooftst02 classes
  14.  
  15.     TEST_CONNECT    theDB;
  16.     dbPatients     Patients;
  17.     dbVisits    Visits;
  18.     dbRelationship PatientVisits(Patients.Visits, Visits.Patient);
  19.     
  20.  
  21. void testRecDeletes();
  22.  
  23. void testRecDeletes()
  24. {
  25.     Patients.start();
  26.     cout << "Deleting individual record - "
  27.         << Patients.LastName << ", "
  28.         << Patients.Othernames  
  29.         << endl << endl;    
  30.     Patients.deleteRecord();
  31.     
  32.     cout << "Should be on next record after delete, which is now first record in file - "
  33.         << Patients.LastName << ", "
  34.         << Patients.Othernames  
  35.         << endl << endl;    
  36.  
  37.     Patients.last();
  38.     cout << "Goto last record in file - "
  39.         << Patients.LastName << ", " 
  40.         << Patients.Othernames  
  41.         << endl << endl;    
  42.  
  43.     Patients.deleteRecord();
  44.     cout << "Should be on first record after deleting last - " 
  45.         << Patients.LastName << ", " 
  46.         << Patients.Othernames  
  47.         << endl << endl;    
  48.  
  49.     Patients.selectAll();
  50.     cout << "Patients  - should be 2 recs" << endl << Patients << endl << endl;
  51.     
  52. }
  53.  
  54.  
  55. int main()
  56. {
  57.     cout << "OOFILE Validation Suite - Test 9\n"
  58.          << "Simple test to demonstrate deleting records" << endl
  59.          << "using the database from ooftst02" << endl;
  60.          
  61.     #ifdef TESTING_DBASE
  62.         #ifdef _Macintosh
  63.             const char* kExistsName =  ":ooftst09:Patients.dbf";
  64.             const char* kDatabaseName = ":ooftst09:";
  65.         #else
  66.             const char* kExistsName =   "Patients.dbf"
  67.             const char* kDatabaseName = "";
  68.         #endif    
  69.  
  70.     #else
  71.         const char* kDatabaseName = "ooftst09.db";
  72.         const char* kExistsName = kDatabaseName;
  73.     #endif
  74.     
  75.     if (dbConnect::fileExists(kExistsName)) {
  76.         theDB.openConnection(kDatabaseName);
  77.     }
  78.     else {
  79.         theDB.newConnection(kDatabaseName);
  80.     }
  81.  
  82.     Patients.AddTestData();  // always add data - file is empty from last run if it exists
  83.  
  84.     cout << "Entire database before deletions" << endl << theDB << endl;
  85.  
  86.     dbView smithVisits(Patients.Visits); 
  87.     smithVisits << Patients.Visits->VisitDate << Patients.Visits->Why; 
  88.  
  89.     Patients.search(Patients.LastName=="Smith");
  90.     cout << "Dumping Smith and his visits: " << endl 
  91.          << Patients << endl 
  92.          << smithVisits << endl;
  93.         
  94.     cout << "Deleting Smith" << endl;
  95.     Patients.deleteRecord();
  96.  
  97.     cout << "Entire database without Smith" << endl << theDB << endl;
  98.     
  99.     cout << "Deleting all remaining records" << endl;
  100.     Patients.deleteAll();
  101.  
  102.     cout << "Entire database  - should be empty" << endl << theDB << endl << endl;
  103.     
  104.     Patients.AddTestData();  
  105.     cout << "Testing record position after deletes, with all recs & no sort order"<< endl;
  106.     testRecDeletes();
  107.     Patients.deleteAll();
  108.  
  109.     Patients.AddTestData();  
  110.     cout << "Test again, with all recs & sort by othername"<< endl << endl;
  111.     Patients.setSortOrder(Patients.Othernames);
  112.     testRecDeletes();
  113.     Patients.deleteAll();
  114.     
  115.     Patients.AddTestData();  
  116.     cout << "Test again, with all recs & non-indexed sort by reverse othername"<< endl << endl;
  117.     Patients.setReverseSortOrder(Patients.Othernames);
  118.     testRecDeletes();
  119.     Patients.deleteAll();
  120.     
  121.     cout << "done" << endl;
  122.  
  123.     return EXIT_SUCCESS;
  124. }       
  125.